#include <iostream>
#include "framework/service_registry.h"
#include "database/redis_pool.h"

using namespace cpp_backend::framework;

int main() {
    auto& pool = cpp_backend::database::RedisPool::Instance();
    if (!pool.Initialize()) {
        std::cerr << "Failed to init Redis pool" << std::endl;
        return 1;
    }

    ServiceRegistry registry(&pool);

    // 构造一个临时实例
    ServiceInstance inst;
    inst.service_name = "registry_test_service";
    inst.host = "127.0.0.1";
    inst.port = 19999;
    inst.instance_id = "registry-test-1";
    inst.weight = 1;
    inst.register_time = std::chrono::system_clock::now().time_since_epoch().count();

    // 注册 + 心跳
    if (!registry.register_service(inst)) {
        std::cerr << "register_service failed" << std::endl;
        return 2;
    }

    // 发现
    auto list = registry.discover(inst.service_name);
    std::cout << "discover size: " << list.size() << std::endl;
    
    // 清理：删除心跳并触发清理
    registry.unregister_service(inst.instance_id);
    registry.health_check();

    return 0;
}

